import 'dart:math';

import 'package:random_lottery_ticket/dlt.dart';

class RandomService {
  final List<int> ssqRedBalls = [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    21,
    22,
    23,
    24,
    25,
    26,
    27,
    28,
    29,
    30,
    31,
    32,
    33
  ];
  final List<int> ssqBlueBalls = [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16
  ];
  final List<int> dltRedBalls = [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    21,
    22,
    23,
    24,
    25,
    26,
    27,
    28,
    29,
    30,
    31,
    32,
    33,
    34,
    35
  ];
  final List<int> dltBlueBalls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

  /**
    *  num 随机注数
    *  type 随机种类
    */
  List<String> NormalRandom(int num, int type) {
    switch (type) {
      case 0:
        // 双色球
        var ssqList = getssq(num);
        return ssqList;
      case 1:
        //大乐透
        var dltList = getdlt(num);
        return dltList;
    }
  }

  String ChangeNumberToString(int num) {
    if (num < 10) {
      return "0" + num.toString();
    }
    return num.toString();
  }

  List<String> getssq(int num) {
    int ssqrblength = ssqRedBalls.length;
    int ssqbblength = ssqBlueBalls.length;
    var ran = new Random();
    var ssqs = Set<int>();
    var rbs = List<int>();
    var ssqtostring = List<String>();
    var ssqList = List<String>();
    int bb;
    for (int m = 0; m < num; m++) {
      for (int i = 0; i < ssqrblength + 1; i++) {
        int index = ran.nextInt(ssqrblength);
        ssqs.add(ssqRedBalls[index]);
        if (6 == ssqs.length) {
          break;
        }
      }
      rbs.addAll(ssqs);
      rbs.sort();
      int bbindex = ran.nextInt(ssqbblength);
      bb = ssqBlueBalls[bbindex];
      rbs.add(bb);
      for(int j=0;j<rbs.length;j++){
        ssqtostring.add(ChangeNumberToString(rbs[j]));
      }
      ssqList.addAll(ssqtostring);
      ssqs.clear();
      rbs.clear();
      ssqtostring.clear();
    }
    return ssqList;
  }

  List<String> getdlt(int num) {
    int dltrblength = dltRedBalls.length;
    int dltbblength = dltBlueBalls.length;
    var ran = new Random();
    var dlts = Set<int>();
    var dltbbsset = Set<int>();
    var dltbbs = List<int>();
    List<int> dltrbs = List<int>();
    var dlttemp = List<String>();
    var dltLists = List<String>();
    for (int m = 0; m < num; m++) {
      for (int i = 0; i < dltrblength + 1; i++) {
        int index = ran.nextInt(dltrblength);
        dlts.add(dltRedBalls[index]);
        if (5 == dlts.length) {
          break;
        }
      }
      dltrbs.addAll(dlts);
      dltrbs.sort();
      for (int j = 0; j < dltbblength + 1; j++) {
        int index = ran.nextInt(dltbblength);
        dltbbsset.add(dltBlueBalls[index]);
        if (2 == dltbbsset.length) {
          break;
        }
      }
      dltbbs.addAll(dltbbsset);
      dltbbs.sort();
      dltrbs.addAll(dltbbs);
      for(int a=0;a<dltrbs.length;a++){
        dlttemp.add(ChangeNumberToString(dltrbs[a]));
      }
      dltLists.addAll(dlttemp);
      dlts.clear();
      dltbbsset.clear();
      dltrbs.clear();
      dltbbs.clear();
      dlttemp.clear();
    }
    return dltLists;
  }

  double getOnePiece(a,b){
    int m = 1;
    int n = 1;
    int o = 1;
    for(int i=1;i<=a;i++){
      m = m*i;
    }
    for(int j=1;j<=a-b;j++){
      n= n*j;
    }
    for(int l=1;l<=b;l++){
      o = o*l;
    }
    return m/n/o;
  }

}
